package com.wx.ssm.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import java.util.Arrays;

/**
 * @author shkstart
 * @create 2020-05-08 15:10
 */

public class LogSchema {
    //前置通知方法
    public void before() throws Throwable {
        System.out.println("【Schema】前置通知");
    }
    //后置通知方法
    public void afterReturning(JoinPoint jp, Object returningValue) throws Throwable {
        System.out.println("【Schema】后置通知，目标对象"+jp.getTarget()+"，方法名"+jp.getSignature().getName()+"，参数列表"+ Arrays.toString(jp.getArgs())+"，返回值为："+returningValue);
    }
    //异常通知方法
    public void whenException(NullPointerException e){
        System.out.println("【Schema】异常通知:"+e.getMessage());
    }
    //环绕通知配置
    public void around(ProceedingJoinPoint jp){
        //方法执行之前：前置通知
        System.out.println("【Schema-环绕】前置通知");
        try{
            //方法执行时
            jp.proceed();
            //方法执行之后：后置通知
            System.out.println("【Schema-环绕】后置通知");
        }catch (Throwable e){
            //发生异常时：异常通知
            System.out.println("【Schema-环绕】异常通知");
        }finally {
            //最终通知
            System.out.println("【Schema-环绕】最终通知");
        }
    }

}

